home *** CD-ROM | disk | FTP | other *** search
/ SVM Mac 1 / CD-ROM N°1.iso / Utilitaires / Programmation⁄Infos / CDEF Pack 1.1 / CDEF Sampler Program ƒ / samplerControls.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  4.4 KB  |  228 lines  |  [TEXT/KAHL]

  1. #include "samplerControls.h"
  2.  
  3. ControlHandle        rocketCntl, timeButtonCntl, timeCntl, dateCntl;
  4. DateTimeRec            *theTime;
  5.  
  6. extern WindowPtr    samplerWindow;
  7.  
  8. void  SetUpWindowCntls( void )
  9. {
  10. Rect    ctrlRect;
  11.  
  12.     SetRect(&ctrlRect, 5,15,37,47);
  13.     rocketCntl = NewControl( samplerWindow, &ctrlRect, "\p", 
  14.                 TRUE, 0, 0, 1, 1000*16 + 0, 0 );
  15.                 
  16.     SetRect(&ctrlRect, 5,55,37,87);
  17.     timeButtonCntl = NewControl( samplerWindow, &ctrlRect, "\p", 
  18.                 TRUE, 0, 0, 1, 1000*16 + 1, 0 );
  19.     
  20.     theTime = (DateTimeRec *)NewPtrClear(sizeof(DateTimeRec));
  21.     GetTime( theTime );
  22.     
  23.     SetRect(&ctrlRect, 15,95,180,115);
  24.     timeCntl = NewControl( samplerWindow, &ctrlRect, "\pTime Control", TRUE,
  25.                             0, 0, 128, 16*1001 + kTimeVariation, 
  26.                             (long)(theTime));
  27.  
  28.     SetRect(&ctrlRect, 15,120,180,140);
  29.     dateCntl = NewControl( samplerWindow, &ctrlRect, "\pTime Control", TRUE,
  30.                             0, 0, 128, 16*1001 + kDateVariation, 
  31.                             (long)(theTime));
  32. }
  33.  
  34. long ticks, curWait;
  35.  
  36. void    HandleTimeCDEFClick(Point    where)
  37. {
  38. short            thePart, trackPart;
  39. ControlHandle    ch;
  40.  
  41.     ticks = TickCount();
  42.     curWait = 60;
  43.     trackPart = TrackControl( timeCntl, where, TimeCDEFAction);
  44.     
  45.     if (trackPart)
  46.     {
  47.         HandleTimeCDEFPart( timeCntl, trackPart);
  48.     }
  49. }
  50. void    HandleDateCDEFClick(Point    where)
  51. {
  52. short            thePart, trackPart;
  53. ControlHandle    ch;
  54.  
  55.     ticks = TickCount();
  56.     curWait = 60;
  57.     trackPart = TrackControl( dateCntl, where, DateCDEFAction);
  58.     
  59.     if (trackPart)
  60.     {
  61.         HandleDateCDEFPart( dateCntl, trackPart);
  62.     }
  63. }
  64.  
  65. pascal void TimeCDEFAction( ControlHandle ch, short part)
  66. {
  67.     if (TickCount() >= ticks + curWait)
  68.     {
  69.         HandleTimeCDEFPart( ch, part);
  70.         ticks = TickCount();
  71.         curWait = 15;
  72.     }
  73. }
  74. pascal void DateCDEFAction( ControlHandle ch, short part)
  75. {
  76.     if (TickCount() >= ticks + curWait)
  77.     {
  78.         HandleDateCDEFPart( ch, part);
  79.         ticks = TickCount();
  80.         curWait = 15;
  81.     }
  82. }
  83.  
  84. void HandleTimeCDEFPart( ControlHandle ch, short part)
  85. {
  86. DateTimeRec        *theTime;
  87. unsigned long    timeNum;
  88.  
  89.     switch (part)
  90.     {
  91.         case kHourItem:
  92.             SetCtlValue( ch, kHourItem);
  93.             break;
  94.         case kMinItem:
  95.             SetCtlValue( ch, kMinItem);
  96.             break;
  97.         case kAMPMItem:
  98.             SetCtlValue( ch, kAMPMItem);
  99.             break;
  100.         case kArrowButtonUp:
  101.             theTime = (DateTimeRec *)GetCRefCon(ch);
  102.             switch (GetCtlValue(ch))
  103.             {
  104.                 case kHourItem:
  105.                     if (theTime->hour < 23)
  106.                     {
  107.                         (theTime->hour)++;
  108.                     }
  109.                     break;
  110.                 case kMinItem:
  111.                     if (theTime->minute < 59)
  112.                     {
  113.                         (theTime->minute)++;
  114.                     }
  115.                     break;
  116.                 case kAMPMItem:
  117.                     if ( (theTime->hour + 12) <= 23)
  118.                     {
  119.                         (theTime->hour)  += 12;
  120.                     }
  121.                     break;
  122.             }
  123.             Draw1Control( ch );
  124.             break;
  125.         case kArrowButtonDown:
  126.             theTime = (DateTimeRec *)GetCRefCon(ch);
  127.             switch (GetCtlValue(ch))
  128.             {
  129.                 case kHourItem:
  130.                     if (theTime->hour > 0)
  131.                     {
  132.                         (theTime->hour)--;
  133.                     }
  134.                     break;
  135.                 case kMinItem:
  136.                     if (theTime->minute > 0)
  137.                     {
  138.                         (theTime->minute)--;
  139.                     }
  140.                     break;
  141.                 case kAMPMItem:
  142.                     if ( (theTime->hour - 12) >= 0)
  143.                     {
  144.                         (theTime->hour)  -= 12;
  145.                     }
  146.                     break;
  147.             }
  148.             Draw1Control( ch );
  149.             break;
  150.         default:
  151.             SetCtlValue( ch, 0);
  152.             break;
  153.     }
  154. }
  155. void HandleDateCDEFPart( ControlHandle ch, short part)
  156. {
  157. DateTimeRec        *theTime;
  158. unsigned long    timeNum;
  159.     switch (part)
  160.     {
  161.         case kMonthItem:
  162.             SetCtlValue( ch, kMonthItem);
  163.             break;
  164.         case kDateItem:
  165.             SetCtlValue( ch, kDateItem);
  166.             break;
  167.         case kYearItem:
  168.             SetCtlValue( ch, kYearItem);
  169.             break;
  170.         case kDayOfWeekItem:
  171.             SetCtlValue( ch, kDayOfWeekItem);
  172.             break;
  173.         case kArrowButtonUp:
  174.             theTime = (DateTimeRec *)GetCRefCon(ch);
  175.             switch (GetCtlValue(ch))
  176.             {
  177.                 case kMonthItem:
  178.                     if (theTime->month < 12)
  179.                     {
  180.                         (theTime->month)++;
  181.                     }
  182.                     break;
  183.                 case kDateItem:
  184.                 case kDayOfWeekItem:
  185.                     (theTime->day)++;
  186.                     Date2Secs(theTime, &timeNum);
  187.                     Secs2Date(timeNum, theTime);
  188.                     break;
  189.                 case kYearItem:
  190.                     if (theTime->year < 2040)
  191.                     {
  192.                         (theTime->year)++;
  193.                     }
  194.                     break;
  195.             }
  196.             Draw1Control( ch );
  197.             break;
  198.         case kArrowButtonDown:
  199.             theTime = (DateTimeRec *)GetCRefCon(ch);
  200.             switch (GetCtlValue(ch))
  201.             {
  202.                 case kMonthItem:
  203.                     if (theTime->month > 1)
  204.                     {
  205.                         (theTime->month)--;
  206.                     }
  207.                     break;
  208.                 case kDateItem:
  209.                 case kDayOfWeekItem:
  210.                     (theTime->day)--;
  211.                     Date2Secs(theTime, &timeNum);
  212.                     Secs2Date(timeNum, theTime);
  213.                     break;
  214.                 case kYearItem:
  215.                     if (theTime->year > 1904)
  216.                     {
  217.                         (theTime->year)--;
  218.                     }
  219.                     break;
  220.             }
  221.             Draw1Control( ch );
  222.             break;
  223.         default:
  224.             SetCtlValue( ch, 0);
  225.             break;
  226.     }
  227. }
  228.